﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace ChEngine
{
    public class Perf
    {
        IBitBoard board;
        IMoveGenerator generator;
        int nOfLoops;
        
        public Perf(IBitBoard board,IMoveGenerator generator,int nOfLoops)
        {
            this.nOfLoops = nOfLoops;
            this.board = board;
            this.generator = generator;
        }
        public unsafe PerfResults TestGeneratorPerformance()
        {
            int [] moves = new int[100];
            PerfResults res = new PerfResults();
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < nOfLoops; ++i)
            {
               res.MovesCount +=(ulong) generator.GetMoves(board, moves, 0, MoveGenerationMode.All);
            }
            sw.Stop();
            res.Elapsed = (ulong)sw.ElapsedMilliseconds;
            return res;
        }
        public unsafe PerfResults TestDoUndoMove()
        {
            int[] moves = new int[100];
            PerfResults res = new PerfResults();
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < nOfLoops; ++i)
            {
                int n = generator.GetMoves(board, moves, 0, MoveGenerationMode.All);
                res.MovesCount += (ulong)n;
                for (int m = 0; m < n; ++m)
                {
                    board.DoMove(moves[m]);
                    board.UndoMove(moves[m]);
                }
            }
            sw.Stop();
            res.Elapsed = (ulong)sw.ElapsedMilliseconds;
            return res;
        }
    }
}
